// License Notification
//======================================================
// Copyright (c) 2010 Channel Intelligence Inc.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// ======================================================




using System;
using System.Collections.Generic;
using CIP4.Common;

namespace CIP4.RulesEngine
{
    class RulesEngineDataPacket: IDataPacketType
    {
        private object _value;

        private string _rootName;

        #region IDataPacketType Members

        public void Bind(string rootName, object value)
        {
            _rootName = rootName;

            _value = value;
        }

        public LoggerDelegate Logger { get; set; }

        public ActionUsageEnum PacketUsage { get; set; }

        private RulesEngineOperationsType m_Operations;
        public IRulesEngineOperationsType Operations
        {
            get
            {
                if (m_Operations == null)
                    m_Operations = new RulesEngineOperationsType(this);
                return m_Operations;
            }
            set { m_Operations = (RulesEngineOperationsType)value; }
        }

        IRulesEngineOperationsType IDataPacketType.Operations
        {
            get
            {
                if (m_Operations == null)
                    m_Operations = new RulesEngineOperationsType(this);
                return m_Operations;
            }
            set { m_Operations = (RulesEngineOperationsType)value; }
        }

        public IPacketStatsType PacketStats { get; set; }

        IPacketStatsType IDataPacketType.PacketStats
        {
            get
            {
                return PacketStats;
            }
            set
            {
                PacketStats = value;
            }
        }


        public object GetNamedValue(string name)
        {
            if (_rootName == name)
                return _value;
            return null;
        }

        public Dictionary<string, object> Parameters
        {
            get { throw new NotImplementedException(); }
        }

        public void Reset()
        {
        }

        public void Run(string name, string script)
        {
        }

        void IDataPacketType.Reset()
        {
        }

        public GetValueDelegate GetValue{ get; set; }

        public SetValueDelegate SetValue { get; set; }

        #endregion
    }
}
